package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManagerService;
import com.tanhua.model.domain.FreezeDetail;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.vo.MovementsVo;
import com.tanhua.model.vo.PageResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/manage")
public class ManageController {
    @Autowired
    private ManagerService managerService;


    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "10") Integer pagesize,
                                @RequestParam(defaultValue = "1") Integer page) {
        PageResult pageResult = managerService.findAllUsers(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    @GetMapping("/users/{userID}")
    public ResponseEntity userDetails(@PathVariable("userID") Long userId) {
        UserInfo userInfo = managerService.queryUserInfo(userId);
        return ResponseEntity.ok(userInfo);
    }

    @GetMapping("/messages")
    public ResponseEntity movementsList(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize,
                                        Long uid, String state) {
        Integer status = null;
        if (!StringUtils.isEmpty(state) && !"''".equals(state)) {
            status = Integer.valueOf(state);
        }
        PageResult pageResult = managerService.movementsList(page, pagesize, uid, status);
        return ResponseEntity.ok(pageResult);
    }

    @GetMapping("/videos")
    public ResponseEntity videoList(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize,
                                    Long uid) {
        PageResult pageResult = managerService.videoList(page, pagesize, uid);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 接口名称：用户冻结操作
     * 接口路径：POST/manage/users/freeze
     * @return
     */
    @PostMapping("/users/freeze")
    public ResponseEntity freeze(@RequestBody FreezeDetail freezeDetail) {
        Map<String , String > map= managerService.freeze(freezeDetail);
        return ResponseEntity.ok(map);
    }

    /**
     * 接口名称：用户解冻操作
     * 接口路径：POST/manage/users/unfreeze
     * @return
     */
    @PostMapping("/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody FreezeDetail freezeDetail) {
        Map<String , String > map= managerService.unfreeze(freezeDetail);
        return ResponseEntity.ok(map);
    }

}
